package com.rzhkj.box.ctrl;

import com.beust.jcommander.internal.Maps;
import com.rzhkj.box.entity.Account;
import com.rzhkj.box.service.AccountSV;
import com.rzhkj.core.entity.BeanRet;
import com.rzhkj.core.exceptions.BaseException;
import com.rzhkj.core.tools.Md5;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Map;


/**
 * 账户控制器
 *
 * @author lixin
 */
@Controller
@RequestMapping("/account")
@Api(value = "账户控制器", description = "账户控制器")
public class AccountCtrl {
    protected final static Logger logger = LoggerFactory.getLogger(AccountCtrl.class);

    @Resource
    private AccountSV accountSV;


    /**
     * 修改密码
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改密码", notes = "修改密码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "password", value = "密码", required = true, paramType = "query")
    })
    @PutMapping("/modify/password")
    @ResponseBody
    public BeanRet modifyPassword(String password, String token) {
        Assert.hasText(password, BaseException.BaseExceptionEnum.Empty_Param.toString());
//        String accountCode = JwtToken.getTokenValue(token, Constants.AccountCode.val.toString());
        Map<String, Object> map = Maps.newHashMap();
//        map.put("code", accountCode);
        Account accountLoad = accountSV.load(map);
        accountLoad.setPassword(Md5.md5(password));
        accountSV.update(accountLoad);
        return BeanRet.create(true, "修改密码成功");
    }
}
